#include "Logging.h"
#include <string>
Logging::Logging(LoggingType type)
{
	if(type == RankLevel)
	{
		char rankIndexStr[256];
		memset(rankIndexStr, '\0', 256);
		itoa(gRank, rankIndexStr, 10);
		string tmpStr(rankIndexStr);
		string outputFileName = "Log_rank_" + tmpStr + ".txt";
		fout = new ofstream(outputFileName);
	}
	else if(type == MachineLevel)
	{
		fout = new ofstream("Log.txt");
	}
	mLoggingType = type;
}

Logging::~Logging()
{
	SAFE_DELETE(fout);
}

void Logging::Output(const char *info, bool output2File)
{
	if(output2File)
	{
		if(mLoggingType == MachineLevel)
			(*fout)<<"Rank:"<<gRank<<" "<<info<<std::endl;
		else if(mLoggingType == RankLevel)
			(*fout)<<info<<std::endl;
	}
	else
		cout<<"Rank:"<<gRank<<" "<<info<<std::endl;
}